package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: MinioConfiguration
 * Package: com.atguigu.lease.common.minio
 * Description:
 *
 * @Author 咚咚小圆帽
 * @Create 2025/2/10 15:28
 * @Version 1.0
 */
@Configuration
//启动配置类
@EnableConfigurationProperties(MinioProperties.class)
//只有当minio.endpoint属性存在的时候，该配置类才会生效
@ConditionalOnProperty(name = "minio.endpoint")
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties;

    /**
     * 创建minio客户端
     */
    @Bean
    public MinioClient minioClient() {
        MinioClient minioClient =
                MinioClient.builder()
                        .endpoint(minioProperties.getEndpoint())
                        .credentials(minioProperties.getAccessKey(),
                                minioProperties.getSecretKey())
                        .build();

        return minioClient;
    }

}
